home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / tpjr.com / JOYSTICK.DOC < prev    next >
Encoding:
Text File  |  1990-10-22  |  9.7 KB  |  190 lines

  1.                         TURBO PASCAL JOYSTICK ROUTINES
  2.  
  3.                   Copyright (c) 1989, 1990 David B. Howorth
  4.  
  5.                                 Version 3.0b
  6.  
  7.  
  8. A.  The files.
  9.  
  10.         This file is distributed with two others.  The three files are:
  11.  
  12.     JOYSTICK.DOC    This file.
  13.     JOYSTICK.PAS    The key file, which must be compiled to create JOYSTICK.TPU.
  14.     JOYDEMO.PAS     A demonstration of the routines in JOYSTICK.TPU.
  15.  
  16. B.  What to do if you're in a hurry.
  17.  
  18.         Compile JOYSTICK.PAS to disk.  Then compile JOYDEMO.PAS in memory or 
  19. to disk and run it.  Fool around.  Then read this file and the comments in the 
  20. other files to figure out what you've been doing.
  21.  
  22. C.  What's in it for me.
  23.  
  24.         Although it would be nice to have a nickel for every time NYET and ARGH
  25. have been played, I've never charged anything for NYET and did not distribute
  26. ARGH as shareware until version 4.0.  In keeping with those loose business
  27. practices, I encourage you to give away copies of these files, as long as you
  28. distribute all three files together.  I do, however, prohibit you from selling
  29. them: I may not be smart enough to make money from my efforts, but I'm not
  30. going to let someone else do it without me.
  31.  
  32.         Beginning with this release, however, I am imposing a condition for
  33. the use of compiled versions of these routines in programs that are
  34. distributed, whether commercially or noncommercially.  That condition is
  35. simply that you mail me a disk (either size) with one copy of the executable
  36. program and include any documentation; and, if you distribute your program as
  37. shareware, treat me as registered.  What lies behind this condition is not
  38. a desire to amass a huge software library, but simply curiosity--like 
  39. releasing a helium baloon with a return postcard inside. 
  40.  
  41. D.  What's new in this version.
  42.  
  43.         A lot.  When I wrote version 1 of these routines a few years ago, you  
  44. had to program pretty close to the metal to do anything with the joystick.
  45. Since then the ROM BIOS has been extended to include a service that reports on 
  46. the joystick.  Of course, there are still loads of PCs and XTs out there with
  47. older ROM BIOS, which doesn't know a joystick from Shelley's Ode to the West 
  48. Wind.  This version tries to have it both ways, and I think it succeeds.  The 
  49. key routines are private to the unit and are written in two versions, one set 
  50. of routines using the new BIOS services and another independent of them.  
  51. Procedure variables are declared so that the initialization part of the unit 
  52. can assign the correct procedures to the variables, after checking the date of 
  53. the ROM BIOS (see the private function NewBIOS).  The public routines simply 
  54. incorporate the appropriate procedure variables. 
  55.  
  56.         One note about the initialization process.  NewBIOS checks the ASCII 
  57. date characters at $F000:$FFFB and $FFFC.  According to Peter Norton's New
  58. Programmer's Guide, however, not all IBM compatibles keep their ROM BIOS date 
  59. there.  The way I have written NewBIOS, if there is no date here, JOYSTICK.TPU 
  60. will assume that there is no BIOS support for the joystick and will use my 
  61. "old" (though improved) routines.  That is obviously the best way to ensure 
  62. portability.  If your compatible does not have its ROM BIOS date at the IBM 
  63. location and you know that its BIOS supports the joystick, you can change the 
  64. initialization section of JOYSTICK.PAS so that the procedure variables are 
  65. always set equal to the new routines.  I don't think there would be much
  66. advantage in doing that, however, and it will certainly limit the 
  67. portabilitity of your program.
  68.  
  69.         This release has a slightly rewritten version of OldReadJoy, the 
  70. fundamental procedure of the "old" routines.  In the three years or so that my 
  71. original routine was available, I received only two complaints from users who 
  72. said they had problems with ReadJoy, as OldReadJoy used to be called, but I 
  73. was stunned to learn by accident a few weeks ago that the procedure did not 
  74. work on my own machine unless two joysticks were installed.  As the routine is 
  75. now written, it reads only one joystick at a time; there are separate public 
  76. procedures for each joystick.  In response to requests, I have also added 
  77. comments to OldReadJoy's inline code. 
  78.  
  79. E.  How the non-BIOS routines work.
  80.  
  81.         The IBM joystick port is located at hex 201.  All the information
  82. about both joysticks can be read in the byte at that port.  Each bit reports
  83. on a specific thing, namely:
  84.  
  85.            Bit                 Reports on
  86.  
  87.             0            Joystick A X-Axis Coordinate
  88.             1            Joystick A Y-Axis Coordinate
  89.             2            Joystick B X-Axis Coordinate
  90.             3            Joystick B Y-Axis Coordinate
  91.             4            Joystick A Button #1 (usually the top button)
  92.             5            Joystick A Button #2
  93.             6            Joystick B Button #1
  94.             7            Joystick B Button #2
  95.  
  96.         To read the status of a button, you simply read the relevant bit.  If
  97. the bit is 1, the button is not pressed; if it is 0, the button is pressed.
  98. Aside from the fact that this relationship seems counterintuitive, reading the
  99. buttons is a simple task, easily accomplished with the Turbo Pascal port array
  100. and a little bit masking.
  101.  
  102.         The stick itself is a different story.  How is it possible to get
  103. enough information from one bit?  The answer is that you get it by repeated
  104. reads of the relevant bit.  The process works like this:  when you output
  105. something--anything--to port 201, the lower four bits are all set to 1
  106. automatically.  (I think of this as "nudging" the port.)  The length of time
  107. it takes each bit to return to 0 depends on the position of the stick.  For
  108. example, if Joystick A is all the way to the left, Bit 0 will bounce back to 0
  109. immediately after a nudge.  If it is all the way to the right, it will take
  110. longer to return to 0.  If it is centered, it will take about half as long to
  111. return to 0 as it does when it is all the way to the right.
  112.  
  113.         You can use the Turbo Pascal port array in a loop to make successive
  114. reads of port 201, but that's too slow to be very accurate.  The inline code 
  115. incorporated in OldReadJoy is fast and does the job. 
  116.  
  117. F.  Loose ends.
  118.  
  119.         1.  The buttons.  I am a bit concerned that there may be joysticks out 
  120. there whose buttons work counter to the usual way.  If my routines show that
  121. your buttons are out when they are in and vice versa, you can work around 
  122. that, but you shouldn't have to.  I can easily rewrite JOYSTICK.PAS so that it 
  123. can test the button condition at start-up and assume that that is the out 
  124. position.  I did not want to do that since it might turn out to be pointless 
  125. overhead, but if it needs to be done, let me know and I will fix it in the 
  126. next release. 
  127.  
  128.         2.  Function JoystickPresent.  This function works by reading the
  129. equipment-list word in low memory.  According to Peter Norton's Programmer's
  130. Guide, this information may sometimes be inaccurate.  It may be preferable
  131. simply to ask the user whether he has (or wants to use) a joystick.
  132.  
  133.                                           David Howorth
  134.  
  135.                                           01960 SW Palatine Hill Road
  136.                                           Portland, Oregon 97219
  137.  
  138.                                           CIS User ID: 71600,521
  139.                                           GEnie Addr: D.HOWORTH
  140.  
  141.                                           October 22, 1990
  142.          ----------------end-of-author's-documentation---------------
  143.  
  144.                          Software Library Information:
  145.  
  146.                     This disk copy provided as a service of
  147.  
  148.                            Public (software) Library
  149.  
  150.          We are not the authors of this program, nor are we associated
  151.          with the author in any way other than as a distributor of the
  152.          program in accordance with the author's terms of distribution.
  153.  
  154.          Please direct shareware payments and specific questions about
  155.          this program to the author of the program, whose name appears
  156.          elsewhere in  this documentation. If you have trouble getting
  157.          in touch with the author,  we will do whatever we can to help
  158.          you with your questions. All programs have been tested and do
  159.          run.  To report problems,  please use the form that is in the
  160.          file PROBLEM.DOC on many of our disks or in other written for-
  161.          mat with screen printouts, if possible.  PsL cannot debug pro-
  162.          programs over the telephone, though we can answer questions.
  163.  
  164.          Disks in the PsL are updated  monthly,  so if you did not get
  165.          this disk directly from the PsL, you should be aware that the
  166.          files in this set may no longer be the current versions. Also,
  167.          if you got this disk from another vendor and are having prob-
  168.          lems,  be aware that  some files may have become corrupted or
  169.          lost by that vendor. Get a current, working disk from PsL.
  170.  
  171.          For a copy of the latest monthly software library newsletter
  172.          and a list of the 2,000+ disks in the library, call or write
  173.  
  174.                            Public (software) Library
  175.                                P.O.Box 35705 - F
  176.                             Houston, TX 77235-5705
  177.  
  178.                                  Orders only:
  179.                                 1-800-2424-PSL
  180.                               MC/Visa/AmEx/Discover
  181.  
  182.                           Outside of U.S. or in Texas
  183.                           or for general information,
  184.                               Call 1-713-524-6394
  185.  
  186.                           PsL also has an outstanding
  187.                           catalog for the Macintosh.
  188.  
  189.  
  190.